﻿using BrnMall.Manager.Domain.Blog;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;

namespace BrnMall.Manager.Manager.Blog
{
    public class BlogLikeManager
    {
        static string TableName = "crm_blogLike";

        /// <summary>
        /// 添加一条点赞
        /// </summary>
        /// <param name="model"></param>
        /// <returns></returns>
        public static bool Insert(BlogLike model)
        {
            using (var db = new QDMallDatabase())
            {
               db.Insert(model);
            }
            return model.Id > 0;
        }


        public static BlogLike GetByBlogId(int blogid, int uid)
        {
            using (var db = new QDMallDatabase())
            {
                return db.SingleOrDefault<BlogLike>(string.Format("select * from {0} where BlogId={1} and uid={2}  order by id", TableName, blogid, uid));
            }
        }

        /// <summary>
        /// 获取用户动态点赞数
        /// </summary>
        /// <param name="blogid"></param>
        public static IList<BlogLike> GetList(int blogid)
        {
            using (var db = new QDMallDatabase())
            {
                return db.Fetch<BlogLike>(string.Format("select * from {0} where BlogId={1}  order by id", TableName, blogid));
            }
        }

        /// <summary>
        /// 取消点赞
        /// </summary>
        /// <param name="Msgid"></param>
        /// <returns></returns>
        public static bool DeleteByBlogId(int blogId, int uid)
        {
            int count = 0;
            using (var db = new QDMallDatabase())
            {
                count = db.Execute(string.Format("delete {0} where blogid={1} and uid={2}", TableName, blogId, uid));
            }
            return count > 0 ? true : false;
        }
    }
}